<?php
/**
 * 整个项目的根controller
 *
 * */
require_once(LIB_PATH.'helpers/myHelper.php');
require_once (LIB_PATH.'helpers/verifyHelper.php');
class rootCon extends mylib
{
    public function __construct()
    {
        myresponse::setUtf8();
        myresponse::setExpireTime(0);
        $reg = "/(http[s]?:\/\/.*?)\//i";
        if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'])
        {
            $src = $_SERVER['HTTP_REFERER'];
            preg_match($reg, $src, $match);
            $httpUrl = $match[1];
        }
        else
        {
            $httpUrl = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_ORIGIN']:"";
        }

        if (mysafe::isWhiteDomain($httpUrl))
        {
            header('Access-Control-Allow-Credentials:true');
            header('Access-Control-Allow-Origin:' . $httpUrl);
            header('Access-Control-Allow-Methods:GET');
            header('Access-Control-Allow-Headers:x-requested-with,content-type');
        }
        else
        {//错误
            header('Access-Control-Allow-Origin:http://www.qilaiwan.cn/');
        }

        // 非微信浏览器禁止浏览
        $userAgent = strtolower(myrequest::getBrowser());
        if (!ALLOW_PC_BROWER && strpos($userAgent, 'micromessenger') === false)
        {
            echo "HTTP/1.1 401 Unauthorized";
            die(" pc.html");
        }

        //@todo ,check if is login?

    }


    protected function j($code,$info=null,$data = null,$uid = 0)
    {
        if(IS_WINDOWS || ($code!=0 && !$uid)){//出错时显示真实的人
            j(['code'=>$code,'info'=>$info,'uid'=>mylogin::getUid(false),'data'=>$data]);
        }
        if(IS_DEBUG) $uid = mylogin::getUid(false);

        j(['code'=>$code,'info'=>$info,'uid'=>$uid,'data'=>$data]);
    }

}

?>